package wisecashier

import (
	//"wxsdk/utils/mapstruct"
	"github.com/astaxie/beego"
)
type RspHeader struct {
	StatusCode int      `json:"status_code"`
	Message    string   `json:"message"`
	Success    bool     `json:"success,omitempty"`
}
type PayInfo struct {
	TimeStamp string `json:"timeStamp"`
	PrepayId  string `json:"prepay_id"`
	NonceStr  string `json:"nonceStr"`
	PaySign   string `json:"paySign"`
	OrderNo   string `json:"order_no"`
}

type MicroAppPayResponse struct {
	RspHeader  RspHeader `json:"meta,omitempty"`
	PayInfo    PayInfo   `json:"data,omitempty"`
}

//merchanNo := "WC5c21995294820"
//openid" = "orGWH5DezVOCTMdLRbOXNgriSwG8"
//"currency" = "HKD"
//appid="wx921b213a21e4f1d5"

func MicroAppPay(appId,merchanNo,openId,orderId,amount,currency,productInfo,
                 url,privateKey string)(rsp *MicroAppPayResponse, err error){
	var reqParams map[string]interface{}
	rsp = new(MicroAppPayResponse)
	reqParams = make(map[string]interface{})
	reqParams["merchant_no"] = merchanNo
	reqParams["openid"] = openId
	reqParams["currency"] = currency
	reqParams["amount"] = amount
	reqParams["product_info"] = productInfo
	reqParams["agent_order_id"] = orderId
	reqParams["notify_url"] = url
	reqParams["appid"] = appId
	reqURL := "https://api.wisecashier.com/mini_program_pay"
	sdk := NewSDK(reqURL, merchanNo, []byte(privateKey))
	_, err = sdk.Execute(reqParams, rsp)
	if err != nil {
		beego.Debug("WiseCashier MicroAppPay err:", err.Error())
		return
	}
	return
}

